package com.cutie.entry.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.cutie.core.dao.DBManager;
import com.cutie.core.dao.IBuilder;
import com.cutie.entry.model.PropertyDictionary;

public class PropertyDictionaryDao {

	private static final String find_property_sql = "select * from property_dictionary where property_dictionary_id=?";
	@SuppressWarnings("unchecked")
	public List<PropertyDictionary> getProperties(Integer entryId) throws SQLException{
		try{
			Object[] data = new Object[]{ entryId };
			List<PropertyDictionary> propertyList = (List<PropertyDictionary>)DBManager.executeQuery(find_property_sql, data, new IBuilder(){

				@Override
				public Object build(ResultSet rs) throws SQLException {
					List<PropertyDictionary> list = new ArrayList<PropertyDictionary>();
					while(rs.next()){
						PropertyDictionary property = new PropertyDictionary();
						property.setPropertyDictionaryId(rs.getInt("property_dictionary_id"));
						property.setEntryId(rs.getInt("entry_id"));
						property.setEntryName(rs.getString("entry_name"));
						property.setPropertyName(rs.getString("property_name"));
						property.setPropertyNameCN(rs.getString("property_name_cn"));
						property.setImageSource(rs.getString("image_source"));
						
						list.add(property);
					}
					return list;
				}
				
			});
			return propertyList;
		}catch(SQLException e){
			e.printStackTrace();
			throw e;
		}
	}
}
